package com.iotek.bookstore.web.controlle;

import com.iotek.bookstore.modle.entity.Book;
import com.iotek.bookstore.modle.service.serviceimpl.BookBizImpl;
import net.sf.json.JSON;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/login/bookServlet")
public class BookServlet extends CommonServlet {
    @Override
    public void doInsert(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    public void doUpdate(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    public void doQuery(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Book>books=new BookBizImpl().queryAll();
        JSON json= JSONArray.fromObject(books);
        System.out.println("信息来自--->bookServlet--->doQuery:");
        System.out.println(json.toString());
        resp.getWriter().write(json.toString());
    }
}
